//
//  EFANoticeDetTCell.m
//  efairy
//
//  Created by XiangDongMBP on 2017/8/30.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFANoticeDetTCell.h"
#import <UIImageView+WebCache.h>
#import "EFAModel.h"

@interface EFANoticeDetTCell ()
@property (nonatomic, strong) UIImage *defalutImg;
@end

@implementation EFANoticeDetTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.defalutImg = [UIImage imageNamed:@"global_img_default"];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgViewTapped:)];
    [self.imgView addGestureRecognizer:tapGesture];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)imgViewTapped:(UIGestureRecognizer *)gesture {
    if ([self.delegate respondsToSelector:@selector(noticeDetTCell:imgViewTapped:)]) {
        [self.delegate noticeDetTCell:self imgViewTapped:(UIImageView *)gesture.view];
    }
}

- (void)configViewWithNotImgItem:(EFANotImgItem *)item {
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:item.efairyannouncementimage_imgurl]
                    placeholderImage:self.defalutImg
                           completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                               if (image) {
                                   self.imgHeightConstraint.constant = floor([UIScreen mainScreen].bounds.size.width * image.size.height /image.size.width);
                                   [self imageViewDownload];
                               }
                           }];
}

- (void)imageViewDownload {
    if ([self.delegate respondsToSelector:@selector(noticeDetTCell:imgViewDownload:)]) {
        [self.delegate noticeDetTCell:self imgViewDownload:self.imgView];
    }
}

@end
